const base = require("../base/controllerBase");

class DeviceController extends base {
    async createLog() {
        const {ctx, service} = this;
        try {
            const {body} = ctx.request;
            console.log("收到日志消息", body)
            const model = {
                payload: {type: 'object'},
                topic: {type: 'string'},
            };
            ctx.validate(model, body);
            this.app.eventBus.emit("HTTP_DATA_RECEVED", body);
           // const result = await this.app.deviceMgr.onData(body);
            ctx.body = {status: "ok"};
            ctx.status = 200;
        } catch (e) {
            console.error(e);
            console.log(ctx.request.body);
            const _message = e && e.message ? e.message : this.ERROR_MSG;
            ctx.body = {status: 'error', message: _message, result: e};
            ctx.status = 200;
        }
    }
}

module.exports = DeviceController;
